Repository navigation
Fix rolling-median smoothing and improve part 1 performance - #1564
Merged
Merged
Conversation
- Preserve smoothing when block length is not divisible by the sampling step - Correct trailing median padding and preserve valid zero medians - Use runmed directly for complete data, retaining the zoo fallback - Reduce calibration epoch SD overhead with vapply - Add regression tests
Correct median padding removes a spurious 15-second sleep-period fragment on the final partial day. Update the hip test to expect two complete days, while retaining the wrist partial-day checks.
Avoid full raw-block matrix copies, reduce epoch-mean temporaries, size feature buffers by epoch count, and reuse matrix inputs during fitting. Preserve calibration arithmetic and stopping rules. Expand regression coverage and add a reproducible cached-block benchmark. On the tested block, computation time falls by 39% and R allocations by 52%, with identical calibration results apart from resource logs.
Record profiling results, benchmark methods, numerical validation and remaining optimisation opportunities. Link findings to the relevant commits, mark completed work, and distinguish historical measurements from current performance.
Explicitly restore ndayswindow = 7 when switching from masking strategy 5 to strategy 1, preventing two unrelated parameter warnings in the out-of-range study-dates test.
vincentvanhees
marked this pull request as ready for review
October 28, 2026 16:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves two parts of the part 1 pipeline: rolling-median metric extraction in
g.applymetrics()and calibration ing.calibrate().1. g.applymetrics(): rolling-median correctness and performance
Fixes loss of smoothing when block length is not divisible by the downsampling step, including typical 75 Hz blocks.
stats::runmed()directly for complete data, retaining thezoofallback for missing or short inputs.Angle and rolling-median metrics intentionally change where smoothing or padding was previously incorrect.
Fixes #1562
2. g.calibrate(): computation and allocation overhead
vapply()for epoch SDs with the samesd()calculation.The existing calibration arithmetic, thresholds, solver and stopping rules are retained.
Performance: On a cached block of 6.7 million real samples, the larger calibration refactor reduced median computation time from 1.08 to 0.66 seconds and cumulative R allocations from 2,266 to 1,095 MiB—approximately 39% less computation time and 52% fewer allocated bytes. This baseline already includes the SD-loop optimisation, and the benchmark excludes file reading.
Combined impact and validation
Both changes reduce part 1 processing overhead. Their percentages come from separate workloads and cannot be added. File reading remains a substantial cost, and variable full-file timings prevented a reliable combined end-to-end percentage.
GGIR(mode = 1)run preserves inspection and epoch metrics relative to the preceding implementation.ndayswindowin the study-dates test; that test now runs without unexpected warnings.All runtime changes remain in R, with the public interface and dependencies unchanged.
Checklist before merging:
inst/NEWS.Rdwith a user-readable summary. Please, include references to relevant issues or PR discussions.DESCRIPTION,zenodo.json, andinst/CITATIONfiles.